package com.easychat.entity.enums;

import cn.hutool.core.util.StrUtil;
import com.easychat.utils.StringTools;

/**
 * @author kyle.li
 * @version 1.0
 * @description: TODO
 * @date 2024/7/4 22:14
 */
public enum JoinTypeEnum {
    JOIN(0, "直接加入"),
    APPLY(1, "需要审核");

    private Integer type;
    private String desc;

    JoinTypeEnum(Integer type, String desc){
        this.type = type;
        this.desc = desc;
    }

    public Integer getType(){
        return type;
    }

    public String getDesc(){
        return desc;
    }

    public static JoinTypeEnum getByName(String name){
        try{
            if(StrUtil.isEmpty(name)){
                return null;
            }
            return JoinTypeEnum.valueOf(name.toUpperCase());
        }catch (IllegalArgumentException e){
            return  null;
        }
    }

    public static JoinTypeEnum getByType(Integer joinType){
        for(JoinTypeEnum joinTypeEnum: JoinTypeEnum.values()){
            if(joinTypeEnum.getType().equals(joinType)){
                return joinTypeEnum;
            }
        }
        return null;
    }
}
